package com.deer.wms.inventory.web;

import com.deer.wms.intercept.annotation.User;
import com.deer.wms.intercept.common.data.CurrentUser;
import com.deer.wms.inventory.model.stockTake.StockTakeLog;
import com.deer.wms.inventory.model.stockTake.StockTakeLogDto;
import com.deer.wms.inventory.service.InventoryService;
import com.deer.wms.inventory.service.StockTakeLogService;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


/**
* Created by csl on 2021/04/13.
*/
@Api(description = "盘点记录api接口")
@RestController
@RequestMapping("/stock/take/log")
public class StockTakeLogController {

    @Autowired
    private StockTakeLogService stockTakeLogService;

    @Autowired
    private InventoryService inventoryService;


    /**
     * 保存盘点记录
     * @param stockTakeLogDto
     * @param currentUser
     * @return
     */
    @PostMapping("/insert")
    public Result add(@RequestBody StockTakeLogDto stockTakeLogDto, @ApiIgnore @User CurrentUser currentUser) {
        stockTakeLogService.saveLog(stockTakeLogDto,currentUser);
        return ResultGenerator.genSuccessResult();
    }

    /**
     * 通过盘点下架任务号查询下架记录
     * @param wareId
     * @param cellCode
     * @return
     */
    @GetMapping("/list")
    public Result list(Integer wareId, String cellCode) {
        List<StockTakeLog> list = stockTakeLogService.findList(wareId,cellCode);
        return ResultGenerator.genSuccessResult(list);
    }

    /**
     * 根据盘点任务号查询盘点差异表
     * @param wareId
     * @param stockMasterCode
     * @return
     */
    @GetMapping("/findResidualList")
    public Result findResidualList(Integer pageNum, Integer pageSize, Integer wareId, String stockMasterCode) {
        PageHelper.startPage(pageNum, pageSize);
        List<StockTakeLog> list = stockTakeLogService.findResidualList(wareId,stockMasterCode);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

    /**
     * 通过盘点任务号查询盈亏记录
     * @param wareId
     * @param stockMasterCode
     * @return
     */
    @GetMapping("/findProfitOrLossList")
    public Result findProfitOrLossList(Integer wareId, String stockMasterCode, Integer profitOrLoss) {
        List<StockTakeLog> list = stockTakeLogService.findProfitOrLossList(wareId,stockMasterCode,profitOrLoss);
        return ResultGenerator.genSuccessResult(list);
    }
}

